package com.iris.live.services.data.repositories;

import com.iris.live.services.data.models.报价订单表Model;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by EngLee on 2016/8/14.
 */
@Transactional
public interface 报价订单表Repository extends JpaRepository<报价订单表Model, Integer>, JpaSpecificationExecutor<报价订单表Model> {
    @Modifying
    @Query("update 报价订单表Model m set m.资源释放期限=?2 where m.订单编号=?1")
    int updateReleaseEndDate(int orderId,int days);

    @Modifying
    @Query("update 报价订单表Model m set m.订单状态=?2 where m.订单编号=?1")
    int updateOrderStatusById(Integer id, String status);

    @Query(value = "select count(*) from `报价订单表` \n" +
            "where 订单编号 in  \n" +
            "(select 订单编号 from 报价单表 where 初始报价单号 = (  select 初始报价单号 from 报价单表 where 报价编号 = ?1))\n" +
            " and 订单状态 like '%意向%'",nativeQuery = true)
    int selectCountOrder(Integer offerNumber);


    @Query("SELECT t.订单状态 FROM  报价订单表Model t WHERE t.订单编号=?1")
    String selectOrderState(Integer orderNo);

    @Query("SELECT t  FROM  报价订单表Model t WHERE t.订单编号=?1")
    报价订单表Model findOrderById(Integer orderNo);
}